# -*- coding:utf-8 -*-
from uiautomator import device as d
import unittest
import time
from Common import check_controls_exists
from function.Login import test_login


def test_open_app(self):
    app_text = "BobbyApp"
    try:
        # 按下home按键
        d.press.home()
        time.sleep(1)
        # 按下应用按钮
        d.click(400, 1100)
        time.sleep(1)
        # 按下需要测试的应用
        self.assertEqual(check_controls_exists(app_text), True, msg=app_text + " 按钮不存在")
        d(text=app_text).click()
        print("--------------test_open_app OK")
    except Exception as e:
        print("Error: 没有打开app\n", e)


# 显示设备信息
def test_info():
    print("设备信息：", d.info)


class MyTestSuite(unittest.TestCase):
    # 初始化工作
    def setUp(self):
        print("--------------初始化工作")

    # 退出清理工作
    def tearDown(self):
        print("--------------退出清理工作")

    def test_app(self):
        test_open_app(self)
        time.sleep(2)
        test_login()
        time.sleep(1)
        d.swipe(0, 200, 300, 200, 10)
        time.sleep(1)
        d.press("back")


def test_app():
    test_unit = unittest.TestSuite()
    test_unit.addTest(MyTestSuite().test_app())


if __name__ == '__main__':
    unittest.main()
